package com.example.hasee.zhcd.Activities;

import com.bumptech.glide.Glide;
import com.example.hasee.zhcd.Activities.ChuanWu.ArrivalsActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.AtWorkActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.IceoundRecordActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.LeavePortActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.NearPortActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.OutBusinessActivity;
import com.example.hasee.zhcd.Activities.QianDao.TagActivity;
import com.example.hasee.zhcd.Activities.ShangWu.AtPortActivity;
import com.example.hasee.zhcd.Activities.ShangWu.ReserveFundActivity;
import com.example.hasee.zhcd.Activities.ShenHe.ChangePortActivity;
import com.example.hasee.zhcd.Activities.ShenHe.EntrustActivity;
import com.example.hasee.zhcd.Activities.ShenHe.ShipArchivesActivity;
import com.example.hasee.zhcd.Activities.ShenHe.ShipForecastActivity;
import com.example.hasee.zhcd.Activities.TongJi.CblxActivity;
import com.example.hasee.zhcd.Activities.TongJi.CgscxActivity;
import com.example.hasee.zhcd.Activities.TongJi.DlfcxActivity;
import com.example.hasee.zhcd.Activities.TongJi.DlfsrActivity;
import com.example.hasee.zhcd.Activities.TongJi.SchlActivity;
import com.example.hasee.zhcd.Activities.TongJi.SwjhActivity;
import com.example.hasee.zhcd.Activities.TongJi.WqdlActivity;
import com.example.hasee.zhcd.Activities.TongJi.ZdcbActivity;
import com.example.hasee.zhcd.Activities.XiaoXi.MessageActivity;
import com.example.hasee.zhcd.Activities.XiaoXi.NewMsgActivity;
import com.example.hasee.zhcd.Adapters.ArrivalsListAdapter;
import com.example.hasee.zhcd.Adapters.FrontGridAdapter;
import com.example.hasee.zhcd.Base.BaseActivity;
import com.example.hasee.zhcd.Bean.EventMsg;
import com.example.hasee.zhcd.Bean.IconBean;
import com.example.hasee.zhcd.Bean.ModuleBean;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.GlobalParameter;
import com.example.hasee.zhcd.Util.ProgressDialogUtils;
import com.example.hasee.zhcd.View.BadgeView;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

import static com.umeng.message.proguard.k.C;

public class MainActivity extends BaseActivity implements OnBannerListener {
    private TextView title;
    private ImageView back;
    private ImageView home;
    private Banner banner;
    private ArrayList<IconBean> IconList = new ArrayList<IconBean>();
    private ArrayList<ModuleBean> ModuleList = new ArrayList<ModuleBean>();
    private HashMap<String, String> loginmap = (HashMap<String, String>) GlobalParameter.get("loginmap");
    private ArrayList<String> list_path = new ArrayList<String>();
    private int[] icon_id = {R.id.icon1, R.id.icon2, R.id.icon3, R.id.icon4, R.id.icon5, R.id.icon6};
    private int[] image_id = {R.id.img1, R.id.img2, R.id.img3, R.id.img4, R.id.img5, R.id.img6};
    private int[] text_id = {R.id.txt1, R.id.txt2, R.id.txt3, R.id.txt4, R.id.txt5, R.id.txt6};
    //隐藏动画
    private LinearLayout HiddenLayout;
    private float mDensity;
    private int mHiddenViewMeasuredHeight;
    private ImageView line;
    private int[] line_pics = {R.mipmap.tub_ej1, R.mipmap.tub_ej2, R.mipmap.tub_ej3, R.mipmap.tub_ej4};
    private String OpenTag = "";
    //二级九宫格
    private GridView gridView;
    private FrontGridAdapter adapter;
    private ArrayList<HashMap<String, Object>> er_list = new ArrayList<HashMap<String, Object>>();
    private ArrayList<String> er_string_list = new ArrayList<String>();
    private int er_position;
    private String strCL = "";
    private String strPhone;
    private ImageView RightTop;
    private String token;


    @Override
    public int contentViewId() {
        return R.layout.activity_main;
    }

    @Override
    public void set() {
        back.setVisibility(View.INVISIBLE);
        home.setImageResource(R.mipmap.logout);
        home.setOnClickListener(this);
        title.setText("之海船代");
        HiddenLayout.setVisibility(View.GONE);
        getHomeImg();
        ProgressDialogUtils.createProgressDialog(MainActivity.this, "正在获取首页信息...");
    }

    @Override
    public void init() {

        strPhone = loginmap.get("phone");
        mDensity = getResources().getDisplayMetrics().density;
        title = (TextView) findViewById(R.id.centertitle);
        back = (ImageView) findViewById(R.id.back);
        home = (ImageView) findViewById(R.id.home);
        banner = (Banner) findViewById(R.id.banner);
        gridView = (GridView) findViewById(R.id.gridview);
        HiddenLayout = (LinearLayout) findViewById(R.id.hidden_layout);
        line = (ImageView) findViewById(R.id.line);
    }

    @Override
    public void getEventData(EventMsg msg) {
        switch (msg.getAction()) {
            case "HomeImg":
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    JSONArray urls = json.getJSONArray("data");
                    list_path.clear();
                    for (int i = 0; i < urls.length(); i++) {
                        list_path.add(urls.getJSONObject(i).getString("URL"));
                    }
                    banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
                    //设置图片加载器，图片加载器在下方
                    banner.setImageLoader(new MyLoader());
                    //设置图片网址或地址的集合
                    banner.setImages(list_path);
                    //设置轮播的动画效果，内含多种特效，可点入方法内查找后内逐一体验
                    banner.setBannerAnimation(Transformer.Default);
                    //设置轮播间隔时间
                    banner.setDelayTime(3000);
                    //设置是否为自动轮播，默认是“是”。
                    banner.isAutoPlay(true);
                    //设置指示器的位置，小点点，左中右。
                    banner.setIndicatorGravity(BannerConfig.CENTER)
                            //以上内容都可写成链式布局，这是轮播图的监听。比较重要。方法在下面。
                            .setOnBannerListener(MainActivity.this)
                            .start();
                    //必须最后调用的方法，启动轮播图。

                } catch (Exception e) {
                    e.printStackTrace();
                }
                getModule();
                break;
            case "ZH_Module":
                Log.e("ZH_Module", msg.getMsg());
                ProgressDialogUtils.closeProgressDialog();
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    String rspcode = json.getString("rspcode");
                    if ("0".equals(rspcode)) {
                        JSONArray data = json.getJSONArray("data");
                        ModuleList.clear();
                        for (int i = 0; i < data.length(); i++) {
                            String name = data.getJSONObject(i).getString("menuName");
                            Boolean hasChildMenu;
                            ArrayList<String> childList = new ArrayList<String>();
                            if ("0".equals(data.getJSONObject(i).getString("hasChildrenMenu"))) {
                                hasChildMenu = false;
                            } else {
                                hasChildMenu = true;
                                childList.clear();
                                for (int j = 0; j < data.getJSONObject(i).getJSONArray("childrenMenu").length(); j++) {
                                    childList.add(data.getJSONObject(i).getJSONArray("childrenMenu").getJSONObject(j).getString("menuName"));
                                }
                            }
                            ModuleBean moduleBean = new ModuleBean(name, hasChildMenu, childList);
                            ModuleList.add(moduleBean);
                        }
                        IconList.clear();
                        /*
                        * 问题在后面
                        * */
                        for (int k = 0; k < ModuleList.size(); k++) {
                            IconBean iconbean = new IconBean((LinearLayout) findViewById(icon_id[k]),
                                    (ImageView) findViewById(image_id[k]),
                                    (TextView) findViewById(text_id[k]));
                            iconbean.getIcon().setVisibility(View.VISIBLE);
                            iconbean.getIcon().setTag(ModuleList.get(k).getName());
                            iconbean.getTextView().setText(ModuleList.get(k).getName());
                            if ("船务".equals(ModuleList.get(k).getName())) {
                                iconbean.getImageView().setImageResource(R.mipmap.tub_cw);
                            } else if ("商务".equals(ModuleList.get(k).getName())) {
                                iconbean.getImageView().setImageResource(R.mipmap.tub_sw);
                            } else if ("审核".equals(ModuleList.get(k).getName())) {
                                iconbean.getImageView().setImageResource(R.mipmap.tub_sh);
                            } else if ("统计分析".equals(ModuleList.get(k).getName())) {
                                iconbean.getImageView().setImageResource(R.mipmap.tub_tjfx);
                            } else if ("系统消息".equals(ModuleList.get(k).getName())) {
                                iconbean.getImageView().setImageResource(R.mipmap.tub_xtxx);
                                RightTop = iconbean.getImageView();
                            } else if ("签到".equals(ModuleList.get(k).getName())) {
                                iconbean.getImageView().setImageResource(R.mipmap.tub_qd);
                            }
                            IconList.add(iconbean);
                        }
                        for (int j = 0; j < IconList.size(); j++) {
                            IconList.get(j).getIcon().setOnClickListener(MainActivity.this);
                        }

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                getMsgCount();
                break;
            case "ZH_Signin":
                ProgressDialogUtils.closeProgressDialog();
                //ZH_Signin: {"data":"","rspcode":3,"rspmessage":"签到成功！"}
                //ZH_Signin: {"data":"","rspcode":3,"rspmessage":"已签到！"}
                try {
                    JSONObject json = new JSONObject(msg.getMsg());
                    String rspcode = json.getString("rspcode");
                    String rspmessage = json.getString("rspmessage");
                    Toast.makeText(MainActivity.this, rspmessage, Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case "ZHMsg_Count":
                Log.e("ZHMsg_Count", msg.getMsg());
                //ZHMsg_Count: {"data":"0","rspcode":0,"rspmessage":""}
                try {
//                    JSONObject json = new JSONObject(msg.getMsg());
//                    String rspcode = json.getString("rspcode");
//                    String rspmessage = json.getString("rspmessage");
//                    String data = json.getString("data");
//                    BadgeView badgeView = new BadgeView(MainActivity.this, RightTop);
//                    badgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
//                    badgeView.setText(data);
//                    badgeView.setBadgeMargin(5);
//                    if (!"0".equals(data)) {
//                        badgeView.show();
//                    } else {
//                        badgeView.hide();
//                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    private void getHomeImg() {
        HashMap<String, String> map = new HashMap<String, String>();
        httpUtils.get("HomeImg", map, "HomeImg");
    }

    private void getModule() {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("strRole", loginmap.get("role"));
        httpUtils.get("ZH_Module", map, "ZH_Module");
    }

    private void getDao() {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("strAccount", loginmap.get("account"));
        map.put("strCL", strCL);
        httpUtils.get("ZH_Signin", map, "ZH_Signin");
    }

    private void getMsgCount() {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("strPhone", strPhone);
        httpUtils.get("ZHMsg_Count", map, "ZHMsg_Count");
    }

    private void animateOpen(View v) {
        v.setVisibility(View.VISIBLE);
        ValueAnimator animator = createDropAnimator(v, 0,
                mHiddenViewMeasuredHeight);
        animator.start();
    }

    private void animateClose(final View view) {
        int origHeight = view.getHeight();
        ValueAnimator animator = createDropAnimator(view, origHeight, 0);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }

        });
        animator.start();
    }

    private ValueAnimator createDropAnimator(final View v, int start, int end) {
        ValueAnimator animator = ValueAnimator.ofInt(start, end);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator arg0) {
                int value = (int) arg0.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
                layoutParams.height = value;
                v.setLayoutParams(layoutParams);

            }
        });
        return animator;
    }

    @Override
    public void OnBannerClick(int position) {

    }

    private class MyLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load((String) path).into(imageView);
        }
    }

    @Override
    public void onClick(View view) {
        switch ((String) view.getTag()) {
            case "船务":
                for (int i = 0; i < ModuleList.size(); i++) {
                    if ("船务".equals(ModuleList.get(i).name)) {
                        er_position = i;
                        er_string_list = ModuleList.get(i).getChildList();
                    }
                    if ("船务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_cw);
                    } else if ("商务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sw);
                    } else if ("审核".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sh);
                    } else if ("统计分析".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_tjfx);
                    }
                }
                if (HiddenLayout.getVisibility() == View.GONE) {
                    er_list.clear();
                    for (int j = 0; j < er_string_list.size(); j++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("text", er_string_list.get(j));
                        if ("预抵锚地船舶".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_ydjmdcb);
                        } else if ("靠泊船舶".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_kbcb);
                        } else if ("离港船舶".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_lgcb);
                        } else if ("外勤管理".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_wqgl);
                        } else if ("当班作业情况".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_dbzyqk);
                        } else if ("封航记录".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_fhjl);
                        }
                        er_list.add(map);
                    }
                    adapter = new FrontGridAdapter(MainActivity.this, er_list);
                    gridView.setAdapter(adapter);
                    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            switch (er_string_list.get(i)) {
                                case "预抵锚地船舶":
                                    startActivity(new Intent(MainActivity.this, ArrivalsActivity.class));
                                    break;
                                case "离港船舶":
                                    startActivity(new Intent(MainActivity.this, LeavePortActivity.class));
                                    break;
                                case "外勤管理":
                                    startActivity(new Intent(MainActivity.this, OutBusinessActivity.class));
                                    break;
                                case "靠泊船舶":
                                    startActivity(new Intent(MainActivity.this, NearPortActivity.class));
                                    break;
                                case "当班作业情况":
                                    startActivity(new Intent(MainActivity.this, AtWorkActivity.class));
                                    break;
                                case "封航记录":
                                    startActivity(new Intent(MainActivity.this, IceoundRecordActivity.class));
                                    break;
                            }
                        }
                    });
                    mHiddenViewMeasuredHeight = (int) (mDensity * 230);
                    animateOpen(HiddenLayout);
                    IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_cw1);
                    OpenTag = "船务";
                    line.setImageResource(line_pics[er_position]);
                } else {
                    if ("船务".equals(OpenTag)) {
                        animateClose(HiddenLayout);
                        OpenTag = "";
                    } else {
                        IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_cw1);
                        er_list.clear();
                        for (int j = 0; j < er_string_list.size(); j++) {
                            HashMap<String, Object> map = new HashMap<String, Object>();
                            map.put("text", er_string_list.get(j));
                            if ("预抵锚地船舶".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_ydjmdcb);
                            } else if ("靠泊船舶".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_kbcb);
                            } else if ("离港船舶".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_lgcb);
                            } else if ("外勤管理".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_wqgl);
                            } else if ("当班作业情况".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_dbzyqk);
                            } else if ("封航记录".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_fhjl);
                            }
                            er_list.add(map);
                        }
                        adapter = new FrontGridAdapter(MainActivity.this, er_list);
                        gridView.setAdapter(adapter);
                        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                switch (er_string_list.get(i)) {
                                    case "预抵锚地船舶":
                                        startActivity(new Intent(MainActivity.this, ArrivalsActivity.class));
                                        break;
                                    case "离港船舶":
                                        startActivity(new Intent(MainActivity.this, LeavePortActivity.class));
                                        break;
                                    case "外勤管理":
                                        startActivity(new Intent(MainActivity.this, OutBusinessActivity.class));
                                        break;
                                    case "靠泊船舶":
                                        startActivity(new Intent(MainActivity.this, NearPortActivity.class));
                                        break;
                                    case "当班作业情况":
                                        startActivity(new Intent(MainActivity.this, AtWorkActivity.class));
                                        break;
                                    case "封航记录":
                                        startActivity(new Intent(MainActivity.this, IceoundRecordActivity.class));
                                        break;
                                }
                            }
                        });
                        line.setImageResource(line_pics[er_position]);
                    }
                    OpenTag = "船务";
                }
                break;
            case "商务":
                for (int i = 0; i < ModuleList.size(); i++) {
                    if ("商务".equals(ModuleList.get(i).name)) {
                        er_position = i;
                        er_string_list = ModuleList.get(i).getChildList();
                    }
                    if ("船务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_cw);
                    } else if ("商务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sw);
                    } else if ("审核".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sh);
                    } else if ("统计分析".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_tjfx);
                    }
                }
                if (HiddenLayout.getVisibility() == View.GONE) {
                    er_list.clear();
                    for (int j = 0; j < er_string_list.size(); j++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("text", er_string_list.get(j));
                        if ("在港船舶".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_zgcb);
                        } else if ("备用金查询".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_byjcx);
                        }
                        er_list.add(map);
                    }
                    adapter = new FrontGridAdapter(MainActivity.this, er_list);
                    gridView.setAdapter(adapter);
                    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            switch (er_string_list.get(i)) {
                                case "在港船舶":
                                    startActivity(new Intent(MainActivity.this, AtPortActivity.class));
                                    break;
                                case "备用金查询":
                                    startActivity(new Intent(MainActivity.this, ReserveFundActivity.class));
                                    break;
                            }
                        }
                    });
                    mHiddenViewMeasuredHeight = (int) (mDensity * 230);
                    animateOpen(HiddenLayout);
                    IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_sw1);
                    OpenTag = "商务";
                    line.setImageResource(line_pics[er_position]);
                } else {
                    if ("商务".equals(OpenTag)) {
                        animateClose(HiddenLayout);
                        OpenTag = "";
                    } else {
                        IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_sw1);
                        er_list.clear();
                        for (int j = 0; j < er_string_list.size(); j++) {
                            HashMap<String, Object> map = new HashMap<String, Object>();
                            map.put("text", er_string_list.get(j));
                            if ("在港船舶".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_zgcb);
                            } else if ("备用金查询".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_byjcx);
                            }
                            er_list.add(map);
                        }
                        adapter = new FrontGridAdapter(MainActivity.this, er_list);
                        gridView.setAdapter(adapter);
                        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                switch (er_string_list.get(i)) {
                                    case "在港船舶":
                                        startActivity(new Intent(MainActivity.this, AtPortActivity.class));
                                        break;
                                    case "备用金查询":
                                        startActivity(new Intent(MainActivity.this, ReserveFundActivity.class));
                                        break;
                                }
                            }
                        });
                        line.setImageResource(line_pics[er_position]);
                        OpenTag = "商务";
                    }
                }
                break;

            case "审核":
                for (int i = 0; i < ModuleList.size(); i++) {
                    if ("审核".equals(ModuleList.get(i).name)) {
                        er_position = i;
                        er_string_list = ModuleList.get(i).getChildList();
                    }
                    if ("船务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_cw);
                    } else if ("商务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sw);
                    } else if ("审核".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sh);
                    } else if ("统计分析".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_tjfx);
                    }
                }
                if (HiddenLayout.getVisibility() == View.GONE) {
                    er_list.clear();
                    for (int j = 0; j < er_string_list.size(); j++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("text", er_string_list.get(j));
                        if ("船舶档案".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_cbdash);
                        } else if ("船舶预报".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_cbybsh);
                        } else if ("改港船舶".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_ggcbsh);
                        } else if ("委办事项".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_bbsxsh);
                        }
                        er_list.add(map);
                    }
                    adapter = new FrontGridAdapter(MainActivity.this, er_list);
                    gridView.setAdapter(adapter);
                    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            switch (er_string_list.get(i)) {
                                case "船舶档案":
                                    startActivity(new Intent(MainActivity.this, ShipArchivesActivity.class));
                                    break;
                                case "船舶预报":
                                    startActivity(new Intent(MainActivity.this, ShipForecastActivity.class));
                                    break;
                                case "改港船舶":
                                    startActivity(new Intent(MainActivity.this, ChangePortActivity.class));
                                    break;
                                case "委办事项":
                                    startActivity(new Intent(MainActivity.this, EntrustActivity.class));
                                    break;
                            }
                        }
                    });
                    mHiddenViewMeasuredHeight = (int) (mDensity * 230);
                    animateOpen(HiddenLayout);
                    IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_sh1);
                    OpenTag = "审核";
                    line.setImageResource(line_pics[er_position]);
                } else {
                    if ("审核".equals(OpenTag)) {
                        animateClose(HiddenLayout);
                        OpenTag = "";
                    } else {
                        IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_sh1);
                        er_list.clear();
                        for (int j = 0; j < er_string_list.size(); j++) {
                            HashMap<String, Object> map = new HashMap<String, Object>();
                            map.put("text", er_string_list.get(j));
                            if ("船舶档案".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_cbdash);
                            } else if ("船舶预报".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_cbybsh);
                            } else if ("改港船舶".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_ggcbsh);
                            } else if ("委办事项".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_bbsxsh);
                            }
                            er_list.add(map);
                        }
                        adapter = new FrontGridAdapter(MainActivity.this, er_list);
                        gridView.setAdapter(adapter);
                        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                switch (er_string_list.get(i)) {
                                    case "船舶档案":
                                        startActivity(new Intent(MainActivity.this, ShipArchivesActivity.class));
                                        break;
                                    case "船舶预报":
                                        startActivity(new Intent(MainActivity.this, ShipForecastActivity.class));
                                        break;
                                    case "改港船舶":
                                        startActivity(new Intent(MainActivity.this, ChangePortActivity.class));
                                        break;
                                    case "委办事项":
                                        startActivity(new Intent(MainActivity.this, EntrustActivity.class));
                                        break;
                                }
                            }
                        });
                        line.setImageResource(line_pics[er_position]);
                        OpenTag = "审核";
                    }
                }
                break;
            case "统计分析":
                for (int i = 0; i < ModuleList.size(); i++) {
                    if ("统计分析".equals(ModuleList.get(i).name)) {
                        er_position = i;
                        er_string_list = ModuleList.get(i).getChildList();
                    }
                    if ("船务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_cw);
                    } else if ("商务".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sw);
                    } else if ("审核".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_sh);
                    } else if ("统计分析".equals(IconList.get(i).getIcon().getTag())) {
                        IconList.get(i).getImageView().setImageResource(R.mipmap.tub_tjfx);
                    }
                }
                if (HiddenLayout.getVisibility() == View.GONE) {
                    er_list.clear();
                    for (int j = 0; j < er_string_list.size(); j++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("text", er_string_list.get(j));
                        if ("船公司查询".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_cbzhcx);
                        } else if ("代理费查询".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_cgsdlfcx);
                        } else if ("收入汇总".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_dlfsrhz);
                        } else if ("艘次货量排名".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_cgsschl);
                        } else if ("流向统计".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_cblxtj);
                        } else if ("外勤统计".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_wqdltj);
                        } else if ("重点船舶".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_zdcbcx);
                        } else if ("商务计划".equals(er_string_list.get(j))) {
                            map.put("image", R.mipmap.tub_ej_swjhtj);
                        }
                        er_list.add(map);
                    }
                    adapter = new FrontGridAdapter(MainActivity.this, er_list);
                    gridView.setAdapter(adapter);
                    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            switch (er_string_list.get(i)) {
                                case "船公司查询":
                                    startActivity(new Intent(MainActivity.this, CgscxActivity.class));
                                    break;
                                case "代理费查询":
                                    startActivity(new Intent(MainActivity.this, DlfcxActivity.class));
                                    break;
                                case "收入汇总":
                                    startActivity(new Intent(MainActivity.this, DlfsrActivity.class));
                                    break;
                                case "艘次货量排名":
                                    startActivity(new Intent(MainActivity.this, SchlActivity.class));
                                    break;
                                case "流向统计":
                                    startActivity(new Intent(MainActivity.this, CblxActivity.class));
                                    break;
                                case "外勤统计":
                                    startActivity(new Intent(MainActivity.this, WqdlActivity.class));
                                    break;
                                case "重点船舶":
                                    startActivity(new Intent(MainActivity.this, ZdcbActivity.class));
                                    break;
                                case "商务计划":
                                    startActivity(new Intent(MainActivity.this, SwjhActivity.class));
                                    break;
                            }
                        }
                    });
                    mHiddenViewMeasuredHeight = (int) (mDensity * 230);
                    animateOpen(HiddenLayout);
                    IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_tjfx1);
                    OpenTag = "统计分析";
                    line.setImageResource(line_pics[er_position]);
                } else {
                    if ("统计分析".equals(OpenTag)) {
                        animateClose(HiddenLayout);
                        OpenTag = "";
                    } else {
                        IconList.get(er_position).getImageView().setImageResource(R.mipmap.tub_tjfx1);
                        er_list.clear();
                        for (int j = 0; j < er_string_list.size(); j++) {
                            HashMap<String, Object> map = new HashMap<String, Object>();
                            map.put("text", er_string_list.get(j));
                            if ("船公司查询".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_cbzhcx);
                            } else if ("代理费查询".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_cgsdlfcx);
                            } else if ("收入汇总".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_dlfsrhz);
                            } else if ("艘次货量排名".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_cgsschl);
                            } else if ("流向统计".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_cblxtj);
                            } else if ("外勤统计".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_wqdltj);
                            } else if ("重点船舶".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_zdcbcx);
                            } else if ("商务计划".equals(er_string_list.get(j))) {
                                map.put("image", R.mipmap.tub_ej_swjhtj);
                            }
                            er_list.add(map);
                        }
                        adapter = new FrontGridAdapter(MainActivity.this, er_list);
                        gridView.setAdapter(adapter);
                        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                switch (er_string_list.get(i)) {
                                    case "船公司查询":
                                        startActivity(new Intent(MainActivity.this, CgscxActivity.class));
                                        break;
                                    case "代理费查询":
                                        startActivity(new Intent(MainActivity.this, DlfcxActivity.class));
                                        break;
                                    case "收入汇总":
                                        startActivity(new Intent(MainActivity.this, DlfsrActivity.class));
                                        break;
                                    case "艘次货量排名":
                                        startActivity(new Intent(MainActivity.this, SchlActivity.class));
                                        break;
                                    case "流向统计":
                                        startActivity(new Intent(MainActivity.this, CblxActivity.class));
                                        break;
                                    case "外勤统计":
                                        startActivity(new Intent(MainActivity.this, WqdlActivity.class));
                                        break;
                                    case "重点船舶":
                                        startActivity(new Intent(MainActivity.this, ZdcbActivity.class));
                                        break;
                                    case "商务计划":
                                        startActivity(new Intent(MainActivity.this, SwjhActivity.class));
                                        break;
                                }
                            }
                        });
                    }
                    line.setImageResource(line_pics[er_position]);
                    OpenTag = "统计分析";
                }
                break;
            case "系统消息":
                startActivity(new Intent(MainActivity.this, NewMsgActivity.class));
                break;
            case "签到":
                if ("wq".equals(loginmap.get("role"))) {
                    Intent intent = new Intent(MainActivity.this, TagActivity.class);
                    startActivity(intent);
                } else {
                    ProgressDialogUtils.createProgressDialog(MainActivity.this, "正在极速签到...");
                    getDao();
                }
                break;
            case "home":
                zhuxiaodialog("是否注销当前登录？");
                break;
        }
    }

    private void zhuxiaodialog(String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setMessage(message);
        builder.setTitle("提示");
        builder.setNegativeButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                // TODO Auto-generated method stub
                SharedPreferences sharedPreferences = getSharedPreferences(
                        "userInfo", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPreferences.edit();// 获取编辑器
                editor.putString("yhm", "");
                editor.putString("pwd", "");
                editor.commit();
                Intent intent = new Intent(MainActivity.this, WelcomeActivity.class);
//                intent.putExtra("token", token);
                startActivity(intent);
                MainActivity.this.finish();
            }
        });
        builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                // TODO Auto-generated method stub
                arg0.dismiss();
            }
        });
        builder.create().show();
    }
}
